package server.business.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import server.business.pojo.ReturnBlood;
import server.business.service.ReturnBloodInformationService;
import server.business.service.ReturnBloodService;
import server.business.utils.results.ysl.Result;

@Slf4j
@RequestMapping("/returnblood")
@RestController
public class ReturnBloodController {

    @Autowired
    private ReturnBloodService returnBloodService;
    @Autowired
    private ReturnBloodInformationService returnBloodInformationService;

    /**
     * 分页查询
     * @param currentPage
     * @param pageSize
     * @param
     * @return
     */
    @GetMapping("/normal/{currentPage}/{pageSize}")
    public Result getPage(@PathVariable int currentPage, @PathVariable int pageSize,
                          ReturnBlood returnBlood){
        IPage<ReturnBlood> page = returnBloodService.getPage(currentPage,pageSize,returnBlood);
        if (currentPage > page.getPages()) {
            page = returnBloodService.getPage((int) page.getPages(), pageSize, returnBlood);
        }
        return Result.success(page);
    }

    /**
     * 获取所有待审核退血申请
     * @return
     */
    @RequestMapping("/normal/getAll")
    public Result getAll(){

        return Result.success(returnBloodService.getAll());

    }

    @RequestMapping("/normal/deleteOne")
    public Result deleteOne(String id){
        returnBloodService.deleteOne(id);
        return Result.success("成功");
    };

    @RequestMapping("/normal/addApplication")
    public Result addApplication(ReturnBlood returnBlood){
        returnBloodService.addApplication(returnBlood);
        return Result.success("添加成功");
    }

    @RequestMapping("/normal/addBloodInformation")
    public Result addBloodInformation(String applyId, String bloodId){
        returnBloodService.addBlood(applyId,bloodId);
        return Result.success();
    }

    @RequestMapping("/review/approve")
    public Result approve(ReturnBlood returnBlood){
        returnBloodService.approve(returnBlood);
        return Result.success("成功");
    }

    @RequestMapping("/review/reject")
    public Result reject(ReturnBlood returnBlood){
        returnBloodService.reject(returnBlood);
        return Result.success("成功");
    }
}
